#include "stdafx.h"
#include "Target.h"
#include "Factory.h"


bool CTarget::SortByDis(CTarget& A, CTarget& B)
{
    return A.Distance()<B.Distance();
}

bool CTarget::SortByHP(CTarget& A, CTarget& B)
{
    DWORD hA = A.Helath();
    DWORD hB = B.Helath();

    //if (GET_DB().m_strAttackFirst.Find(A.Name())>=0)
    //{
    //    if (A.Name()!=B.Name())
    //    {
    //        hA = 1;
    //    }
    //}
    //else if GET_DB().m_strAttackFirst.Find(B.Name())>=0()
    //{
    //}
    return hA<hB;
}

bool CTarget::operator==(sGuid guid)
{
    return guid==m_Guid;
}

bool CTarget::operator==(CTarget &target)
{
    return target.GetGuid()==m_Guid;
}

bool CTarget::operator!=(sGuid guid)
{
    return guid!=m_Guid;
}

bool CTarget::operator!=(CTarget &target)
{
    return target.GetGuid()!=m_Guid;
}

//const CTarget & CTarget::operator = (CTarget&T)
//{
//    this->m_Guid = T.GetGuid();
//    this->Update();
//    return *this;
//}

DWORD CTarget::Distance()const
{
    CPlayer* pPlayer = IFactory::getSingleton().GetPlayer();
    if (!pPlayer) return 10;
    DWORD dw = (DWORD)CalcDistance3D(pPlayer->GetPos(), GetPos());
    return dw;
}

NPCFlags CTarget::NPC()const
{
    if (mInstance.IsNPC(UNIT_NPC_FLAG_VENDOR_AMMO)) return UNIT_NPC_FLAG_VENDOR_AMMO;
    if (mInstance.IsNPC(UNIT_NPC_FLAG_VENDOR_FOOD)) return UNIT_NPC_FLAG_VENDOR_FOOD;
    if (mInstance.IsNPC(UNIT_NPC_FLAG_REPAIR)) return UNIT_NPC_FLAG_REPAIR;
    if (mInstance.IsNPC(UNIT_NPC_FLAG_SPIRITHEALER)) return UNIT_NPC_FLAG_SPIRITHEALER;
    if (mInstance.IsNPC(UNIT_NPC_FLAG_VENDOR_POISON)) return UNIT_NPC_FLAG_VENDOR_POISON;
    if (mInstance.IsNPC(UNIT_NPC_FLAG_INNKEEPER)) return UNIT_NPC_FLAG_INNKEEPER;
    if (mInstance.IsNPC(UNIT_NPC_FLAG_VENDOR)) return UNIT_NPC_FLAG_VENDOR;
    return UNIT_NPC_FLAG_NONE;
}

bool CTarget::IsNPC(DWORD eType)const
{
    return mInstance.IsNPC(eType);
}

bool CTarget::IsBug()
{
    bool bRet = false;
    if (GetTickCount()-m_dwRunTime > GET_DB().m_dwBugTime*1000)
    {
        if (HP()>90)
            bRet = true;
    }
    
    if (GetTickCount()-m_dwRunTime > GET_DB().m_dwBugTime*1000)
    {
        if (HP()>50)
            bRet = true;
    }

    if (GetTickCount()-m_dwRunTime > GET_DB().m_dwBugTime*1000)
    {
        bRet = true;
    }
    return bRet;
}